package main

import (
	"fmt"
	"log"
	"net"
	"time"
)

func main() {
	//dial：拨号
	dial, err := net.Dial("tcp", "127.0.0.1:1888")
	if err != nil {
		log.Println(err)
		return
	}
	defer dial.Close()
	fmt.Printf("连接服务器成功，%v\n", dial.RemoteAddr().String())

	go func() {
		_, err := dial.Write([]byte("hello"))
		if err != nil {
			log.Fatal(err)
			return
		}
		time.Sleep(10 * time.Millisecond)

		tmp := make([]byte, 1024)
		n, err := dial.Read(tmp)
		if err != nil {
			log.Fatal(err)
			return
		}
		fmt.Println("收到服务器回复:", string(tmp[:n]))
	}()

	time.Sleep(10 * time.Second)
}
